//
//  DataBase.m
//  EFExtend
//
//  Created by mac on 15/3/8.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "DataBase.h"


@interface DataBase ()

@end

@implementation DataBase
{
    NSMutableArray *boards;
}

- (void)dealloc
{
   
    HM_SUPER_DEALLOC();
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
    
    boards = [[NSMutableArray alloc]init];
    [boards addObject:@{@"title":@"Login",@"subtitle":@"mvp架构初探",@"map":URLFOR_controller(@"Login")}];
    [boards addObject:@{@"title":@"MVP",@"subtitle":@"mvp架构初探",@"map":URLFOR_controller(@"mvp")}];
    [boards addObject:@{@"title":@"照片墙",@"subtitle":@"支持网络下载",@"map":URLFOR_controller(@"photoWall")}];
    [boards addObject:@{@"title":@"数据加密",@"subtitle":@"AES md5 sha",@"map":URLFOR_controller(@"Encrypt")}];

    [self.tableView reloadData];

    self.view.panEnabled = YES;
}
ON_PAN(signal){
    if (signal) {
        INFO(@"xx");
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {
            [self backWithAnimate:YES];
        }
    }
}

#pragma  mark - table delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return boards.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier=@"listCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (!cell) {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        
    }
    NSDictionary *city = [boards objectAtIndex:indexPath.row];
    cell.textLabel.text = [city valueForKey:@"title"];
    cell.detailTextLabel.text = [city valueForKey:@"subtitle"];
    cell.detailTextLabel.textColor = RGB(.5, .5, .5);
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *city = [boards objectAtIndex:indexPath.row];
    NSString *map = [city valueForKey:@"map"];
    NSString *title = [city valueForKey:@"title"];
    UIViewController *c =[self pushToPath:map animated:YES];
    if ([c isKindOfClass:[UINavigationController class]]) {
        [(UINavigationController*)c topViewController].title = title;
    }else{
        c.title = title;
    }
}
@end
